<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>Title</title>
    <!-- JS -->
    <script type="text/javascript" th:src="@{/myconfig/bootstrap/js/jquery.js} " src="myconfig/bootstrap/js/jquery.js"></script>
    <script type="text/javascript" th:src="@{/myconfig/layui/layui.js}" src="myconfig/layui/layui.js"></script>
    <script type="text/javascript" th:src="@{/itemAndTask/js/jquery.params.js}" src="itemAndTask/js/jquery.params.js"></script>



    <!-- CSS -->
    <link th:href="@{/myconfig/layui/css/layui.css}" href="myconfig/layui/css/layui.css"type="text/css" rel="stylesheet" media="all">
    <style>
        body{margin: 20px 20px 20px 0;}
        .demo-carousel{height: 200px; line-height: 200px; text-align: center;}
    </style>
</head>
<body>

<div class="demoTable layui-row"   >
    <div class="layui-inline layui-col-xs8" style="margin-left: 15%">
        子任务内容:
        <div class="layui-form">

            <textarea lay-verify="" id="taskInfo" rows="5" cols="40" placeholder="请输入任务内容" required></textarea>
        </div>
        执行人:
        <div class="layui-form">
            <select name="sx_founder_id" lay-verify="" id="itemTaskWorker" required>
                <option value="">请选择...</option>
            </select>
        </div>
        <br>
       <div style="text-align: center">
           <button class="layui-btn" data-type="reload" onclick="addTask()">添加</button>
       </div>

    </div>
</div>



<script>
    var itemId=$.query.get("itemId");
    var urengcyId=$.query.get("urengcyId");

    //alert(urengcyId)

    ////加载执行人
    function findWorker() {
        $.ajax({
            url: 'itemTask/users'
            //,data:{areaId:areaId}
            , success: function (data) {
                var  itemTaskWorker = document.getElementById("itemTaskWorker");
                for (var i =0;i<data.length;i++){
                    //  alert(data[2].user.user_id);
                    var option = document.createElement("option");
                    option.setAttribute("value",data[i].userId);
                    option.innerText = data[i].userName;
                    itemTaskWorker.appendChild(option);
                    layui.form.render('select');
                }

            }
        })
    }

    function addTask() {
        var taskInfo = $("#taskInfo").val();
        if(taskInfo==""){
            layer.msg('任务内容不能为空', {
                icon: 0
                , time: 800
            });
            return;
        }

        var itemTaskWorker = Number($("#itemTaskWorker").val());
        if(itemTaskWorker==""||itemTaskWorker==0){
            layer.msg('执行人不能为空', {
                icon: 0
                , time: 800
            });
            return;
        }
        //var itemId= Number(itemId);
        $.ajax({
            url: 'itemTask/add'
            ,data:{
                taskInfo:taskInfo,
                itemTaskWorker:itemTaskWorker,
                itemId:Number(itemId),
                itemUrengcy:urengcyId
            }
            , success: function (data) {
            if(data="success"){
                layer.msg('已分配子任务', {
                    icon: 1
                    , time: 800
                },function() {
                    if(urengcyId=="2"){
                        layer.msg('所属事项为紧急事项，已派发督办单', {
                            icon: 7
                            , time: 1000
                        },function() {
                            freshClose()
                        });
                    }else{
                        freshClose()
                    }

                });
            }else {
                layer.msg('子任务创建失败', {
                    icon: 2
                    , time: 800
                },function() {
                    freshClose()
                });
            }

            }
        })
    }


    function freshClose(){
        window.parent.location.reload();//刷新父页面
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        parent.layer.close(index)
    }
</script>
<script>
    var $;
    var element;
    var form;
    layui.use(['layer','element','jquery','laydate','form'],function () {
        form =layui.form;
        layer = layui.layer;
        $ = layui.jquery;
        element = layui.element;
        laydate = layui.laydate;
        findWorker();

    })


</script>

</body>
</html>